package com.spring.sunflower.main.presenter;

import com.blankj.utilcode.util.LogUtils;
import com.google.gson.Gson;
import com.spring.sunflower.base.BaseObserver;
import com.spring.sunflower.base.BasePresenter;
import com.spring.sunflower.bean.NewestBean;
import com.spring.sunflower.main.MainContract;

import io.reactivex.rxjava3.core.Observable;

/**
 * Created by Kevin on 2021/6/1<br/>
 * <p>
 * Describe:<br/>
 */
public class NewestPresenter extends BasePresenter<MainContract.NewestView> {
    private String TAG = "NewestPresenter";

    public NewestPresenter(MainContract.NewestView baseView) {
        super(baseView);
    }

    public void getNewest(int pageIndex) {
        Observable<NewestBean> observable = requestDataSource.requestNewest(pageIndex);
        addDisposable(observable, new BaseObserver<NewestBean>() {

            @Override
            public void onSuccess(NewestBean bean) {
                String json = new Gson().toJson(bean);
                LogUtils.dTag(TAG, "getNewest=" + json);
                baseView.hideLoading();
                    baseView.showNewestData(bean.getDatas());
            }

            @Override
            public void onError(int status,String msg) {

            }
        });
    }
}
